package com.egao.common.module.student.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.egao.common.core.Constants;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.student.entity.StudentSignSet;
import com.egao.common.module.student.mapper.StudentSignSetMapper;
import com.egao.common.module.student.service.StudentSignSetService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学生毕业去向设置服务接口实现类
 * @author lym
 */
@Service
public class StudentSignSetServiceImpl extends ServiceImpl<StudentSignSetMapper, StudentSignSet> implements StudentSignSetService {

    @Override
    public StudentSignSet get() {
        List<StudentSignSet> list = baseMapper.selectList(new QueryWrapper<StudentSignSet>().orderByDesc("id"));
        if (list == null || list.size() == 0) {
            return null;
        }
        return list.get(0);
    }

    @Override
    public JsonResult saveSet(StudentSignSet studentSignSet) {
        // 逻辑删除所有
        UpdateWrapper<StudentSignSet> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("deleted",Constants.DELETED_FALSE);
        baseMapper.update(null,updateWrapper);

        // 添加新的设置
        studentSignSet.setId(null);
        baseMapper.insert(studentSignSet);
        return JsonResult.ok();
    }
}
